﻿using System.Web.Mvc;
using System.Linq;
using Inovout;
using Inovout.Data.Repository;
using Inovout.Data.Service;
using Inovout.Web.Mvc;
using KuaJing.Portal.Cms.Domain;
using System.Collections.Generic;
using Inovout.Data.Domain;

namespace KuaJing.Portal.WebPage.Controllers
{
    [AllowAnonymous, Alias("类别")]
    public class CategoryController : RepositoryController<Category>
    {
        protected override void InitializeDataSources()
        {
            this.AddDataSource(m => m.Parent, () => base.GetService<IRepositoryService<Category>>().FindAll());
        }
        public override ActionResult New()
        {
            var model = new Category { Name = "T1" };
            model.Children.Add(new Category { Name = "T2" });
            ModelService.Save(model);
            return View("Edit", model);
        }
        [HttpGet]
        public ActionResult index(QueryCriteria queryCriteria)
        {
            return View(QueryCriteriaBuilder.FilterFor(m => m.Name, FilterOperation.Eq)
                .FilterFor(m => m.Parent, FilterOperation.Eq).OrderDescendingFor(m => m.Name).Merge(queryCriteria.Orders).Merge(queryCriteria.Filters));
        }

    }
}